package top.minuy.structure.graph.representations.table;

import top.minuy.res.graph.GraphRes;

/**
 * 邻接表测试
 * v2
 * 有向测试
 *
 * @author Minuy
 * @time 9:37
 * @date 2021/11/25
 */
public class Test {
    public static void main(String[] args) {
        System.out.println("图：");
        System.out.println("-> 无向图：");
        UndirectedGraph ug = new UndirectedGraph(GraphRes.ADJ_MATRIX_G_TXT);
        System.out.println(ug);
        UndirectedWeightedGraph uwg = new UndirectedWeightedGraph(GraphRes.G_WEIGHTED_1);
        System.out.println(uwg);

        System.out.println("有向图的度：");
        Graph gd = new Graph(GraphRes.G_DIRECTED_DEGREES_01, true);
        for (int v=0;v<gd.V();v++){
            System.out.println(v+" : "+gd.indegree(v)+","+gd.outdegree(v));
        }

        System.out.println("有向有权图的度：");
        WeightedGraph wgd1 = new WeightedGraph(GraphRes.G_DIRECTED_DEGREES_WEIGHTED_01, true);
        for (int v=0;v<wgd1.V();v++){
            System.out.println(v+" : "+wgd1.indegree(v)+","+wgd1.outdegree(v));
        }

        System.out.println("-> 有向图：");
        System.out.println(" >无权");
        Graph g = new Graph(GraphRes.ADJ_MATRIX_G_TXT, true);
        System.out.println(g);
        show(g);

        System.out.println(" >带权");
        WeightedGraph wg = new WeightedGraph(GraphRes.G_WEIGHTED_1, true);
        System.out.println(wg);
        show(wg);

        System.out.println("倒图：");
        System.out.println(" >无权");
        Graph gdd = g.reverse();
        System.out.println(gdd);
        show(gdd);

        System.out.println(" >带权");
        WeightedGraph wgd2 = wg.reverse();
        System.out.println(wgd2);
        show(wgd2);
    }

    private static void show(Graph g) {
        System.out.println("-------------------");
        for (int v=0;v<g.V();v++){
            for (int w:g.adj(v)){
                System.out.println(v+" -> "+w);
            }
        }
    }

    private static void show(WeightedGraph g) {
        System.out.println("-------------------");
        for (int v=0;v<g.V();v++){
            for (int w:g.adj(v)){
                System.out.println(v+" -> "+w);
            }
        }
    }
}
